/*
 * \brief  Server-side interface for PCI device
 * \author Norman Feske
 * \date   2008-01-28
 */

/*
 * Copyright (C) 2008-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#ifndef _INCLUDE__PCI_DEVICE__SERVER_H_
#define _INCLUDE__PCI_DEVICE__SERVER_H_

#include <pci_device/pci_device.h>
#include <base/server.h>

namespace Pci {

	class Device_server : public Genode::Server_object, public Device
	{
		public:

			int dispatch(int op, Genode::Ipc_istream &is, Genode::Ipc_ostream &os)
			{
				switch (op) {

				case VENDOR_ID:

					os << vendor_id();
					return 0;

				case DEVICE_ID:

					os << device_id();
					return 0;

				case CLASS_CODE:

					os << class_code();
					return 0;

				case RESOURCE:
					{
						int resource_id = 0;
						is >> resource_id;
						os << resource(resource_id);
						return 0;
					}

				case CONFIG_READ:
					{
						unsigned char address = 0;
						Access_size   size    = ACCESS_32BIT;
						is >> address >> size;
						os << config_read(address, size);
						return 0;
					}

				case CONFIG_WRITE:
					{
						unsigned char address = 0;
						unsigned value        = 0;
						Access_size   size    = ACCESS_32BIT;
						is >> address >> value >> size;
						config_write(address, value, size);
						return 0;
					}

				default:

					return -1;
				}
			}
	};
}

#endif /* _INCLUDE__PCI_DEVICE__SERVER_H_ */
